<?php
require_once("rpcl/rpcl.inc.php");
require_once("config/data.php");
//Includes
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");
use_unit("jsval/formvalidator.inc.php");
use_unit("comctrls.inc.php");

//Class definition
class index extends Page
{
    public $FormValidator1 = null;
    public $Label1 = null;
    public $Label2 = null;
    public $Window1 = null;
    public $Editusername = null;
    public $EditPassword = null;
    public $Btnlogin = null;
    public $BtnQuit = null;
    public $Label3 = null;

function indexJSLoad($sender, $params)
    {
        ?>
        //begin js
        Window1.centerToBrowser();
        Window1.open();
        //end
        <?php
    }

    function BtnloginJSClick($sender, $params)
    {
        ?>
        //begin js
         return FormValidator1_validate();
        //end
        <?php
    }
    function BtnloginClick($sender, $params)
    {
     Global $dzsxDB;
     $user=$this->Editusername->Text;
     $pwd=$this->EditPassword->Text;
     //查询学生用户
     if($dzsxDB->Query1->Active)
       $dzsxDB->Query1->close();
     $dzsxDB->Query1->SQL="Select student.* From student Where student.StudentId = '$user'";
     $dzsxDB->Query1->open();
     //查询教师用户
     if($dzsxDB->Query2->Active)
       $dzsxDB->Query2->close();
     $dzsxDB->Query2->SQL="Select teacher.* From teacher Where teacher.TeacherId = '$user'";
     $dzsxDB->Query2->open();

      //查询密码是否正确
     if($dzsxDB->Query1->RecordCount==1)
       {
        $pwd2=$dzsxDB->Query1->fieldget('StudentPwd');
        if($pwd==$pwd2)
          {
           $_SESSION['StuId']="$user";//学生用户Id
           $_SESSION['MenuId']=0;  //菜单显示区分标识
           redirect("student.php");
          }
         else
          {$this->Label3->caption="密码错误！";}
       }
      else if($dzsxDB->Query2->RecordCount==1)
        {
         $TeaType=$dzsxDB->Query2->TeaType;
         $pwd2=$dzsxDB->Query2->fieldget('TeacherPwd');
         if($pwd==$pwd2)
          {
           $_SESSION['TeacherId']="$user";
           $_SESSION['TeacherExpinfo_Flag']=0;
           $_SESSION['TeacherType']=$TeaType;
           redirect("teacher.php");
          }
         else
          {$this->Label3->caption="密码错误！";}
        }
      else
         $this->Label3->caption="用户名错误！";
    }
    function BtnQuitJSClick($sender, $params)
    {
        ?>
        //begin js
          window.close();
        //end
        <?php
    }

    function indexShow($sender, $params)   //解决IE标题乱码
    {
     $this->Caption="塘沽一职实验报告管理系统";
     $this->Label2->Caption="密&nbsp;&nbsp;&nbsp;&nbsp;码";
    }
    function EditusernameJSKeyUp($sender, $params)
    {
        ?>
        //begin js
        if (event.keyCode == 40) // если нажата клавиша "стрелка вниз"
         {
           findObj("EditPassword" ).focus();
          }
        if (event.keyCode == 38) // если нажата клавиша "стрелка вверх"
          {
            findObj("Btnlogin").focus();
          }
        //end
        <?php
    }

}

global $application;

global $index;

//Creates the form
$index=new index($application);

//Read from resource file
$index->loadResource(__FILE__);

//Shows the form
$index->show();

?>